package net.wyf.codetest.ui;

import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import net.wyf.codetest.R;
import net.wyf.codetest.entity.PieData;
import net.wyf.codetest.widget.PieView;
import net.wyf.codetest.widget.ScoreView;
import net.wyf.codetest.widget.TopBarView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private PieView pieView;
    private TopBarView topBarView;
    private LinearLayout scoreLinearLayout;
    private ImageView showImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pieView = (PieView) findViewById(R.id.pieviewId);
        topBarView = (TopBarView) findViewById(R.id.topbarId);
        scoreLinearLayout = (LinearLayout) findViewById(R.id.score_view);
        showImageView = (ImageView) findViewById(R.id.showImageViewId);
        showImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                showImageView.setImageBitmap(cuteImage(scoreLinearLayout));
                startActivity(new Intent(MainActivity.this,SecondActivity.class));
            }

        });


        scoreLinearLayout.addView(new ScoreView(this, 100, 120));

        ArrayList<PieData> datas = new ArrayList<>();
        datas.add(new PieData("1", 100));
        datas.add(new PieData("1", 200));
        datas.add(new PieData("1", 300));
        datas.add(new PieData("1", 500));
        pieView.setData(datas);
        pieView.setStartAngle(76);

        topBarView.setOnTopbarClickListener(new TopBarView.OnTopBarClickListener() {
            @Override
            public void leftClick() {
                Toast.makeText(MainActivity.this, "left", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void rightClick() {
                Toast.makeText(MainActivity.this, "right", Toast.LENGTH_SHORT).show();
            }
        });


    }

    //截一部分图片
    private Bitmap cuteImage(View view) {
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
        view.setDrawingCacheEnabled(false);
        return bitmap;
    }
}
